-
Notifications
You must be signed in to change notification settings - Fork 274
/
index.ts
58 lines (47 loc) · 1.89 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { AdaptiveDialog, SendActivity, OnIntent, OnDialogEvent, OnUnknownIntent, IfCondition, SetProperty } from "botbuilder-dialogs-adaptive";
import { getRecognizer } from "../recognizer";
import { AddToDo } from "../addToDo";
import { DeleteToDo } from "../deleteToDo";
import { ClearToDos } from "../clearToDos";
import { ShowToDos } from "../showToDos";
export class RootDialog extends AdaptiveDialog {
constructor() {
super('main');
// Bind to production/development recognizer
this.recognizer = getRecognizer();
// Handle recognized intents
this.addRule(new OnIntent('#AddToDo', [], [
new AddToDo()
]));
this.addRule(new OnIntent('#DeleteToDo', [], [
new DeleteToDo()
]));
this.addRule(new OnIntent('#ClearToDos', [], [
new ClearToDos()
]));
this.addRule(new OnIntent('#ShowToDos', [], [
new ShowToDos()
]));
this.addRule(new OnUnknownIntent([
new IfCondition(`user.greeted != true`, [
new SendActivity(`Hi! I'm a ToDo bot. Say "add a todo named first one" to get started.`),
new SetProperty(`user.greeted`, `true`)
]).else([
new SendActivity(`Say "add a todo named first one" to get started.`)
])
]));
// Define rules to handle cancel events
this.addRule(new OnDialogEvent('cancelAdd', [
new SendActivity(`Ok... Cancelled adding new todo.`)
]));
this.addRule(new OnDialogEvent('cancelDelete', [
new SendActivity(`Ok...`)
]));
// Define rules for handling errors
this.addRule(new OnDialogEvent('error', [
new SendActivity(`Oops. An error occurred: {message}`)
]));
}
}